package com.tools.common.container.r;

import com.tools.common.exception.InvalidOperationException;
import com.tools.common.object.Note;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.function.Predicate;
/**
 * 只读 TreeSet 集合
 * */
@Note("只读 TreeSet 集合")
public final class OnlyReadTreeSet<T> extends TreeSet<T> {

    public OnlyReadTreeSet() {
        super();
    }

    @SafeVarargs
    public OnlyReadTreeSet(T... elements) {
        super();
        if(elements == null || elements.length == 0) return;
        for(T obj : elements) super.add(obj);
    }

    @SafeVarargs
    public OnlyReadTreeSet(Comparator<? super T> comparator, T... elements) {
        super(comparator);
        if(elements == null || elements.length == 0) return;
        for(T obj : elements) super.add(obj);
    }

    public OnlyReadTreeSet(Iterable<? extends T> elements) {
        super();
        if(elements == null) return;
        for(T obj : elements) super.add(obj);
    }

    public OnlyReadTreeSet(Comparator<? super T> comparator, Iterable<? extends T> elements) {
        super(comparator);
        if(elements == null) return;
        for(T obj : elements) super.add(obj);
    }



    @Override
    public boolean add(T t) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean addAll(Collection<? extends T> c) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean remove(Object o) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean removeIf(Predicate<? super T> filter) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public boolean retainAll(@NotNull Collection<?> c) {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public void clear() {
        throw new InvalidOperationException("该 Set 集合只支持读操作");
    }

    @Override
    public T pollFirst() {
        throw new InvalidOperationException("该 Set 集合只支持读操作，不能使用 poll 操作");
    }

    @Override
    public T pollLast() {
        throw new InvalidOperationException("该 Set 集合只支持读操作，不能使用 poll 操作");
    }
}
